package com.ygqh.baby.controller.admin;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ygqh.baby.ao.DataStatus;
import com.ygqh.baby.ao.Message;
import com.ygqh.baby.ao.QueryInfo;
import com.ygqh.baby.ao.ResultSet;
import com.ygqh.baby.po.YgStyle;
import com.ygqh.baby.service.YgStyleService;

@Controller
@RequestMapping("/admin/style")
public class StyleController  extends BaseController<Object, java.lang.Long>{
	
    @Autowired
	private YgStyleService ygStyleService;	
	
	@RequestMapping("searchStyle")
	@ResponseBody
	public Map<String,Object> searchStyle(String q,QueryInfo queryInfo) {	
		
		ResultSet<YgStyle> resultSet=ygStyleService.search(queryInfo,getSession().getSupplierId(),q);
		
		return resultSet.toDatatables(null);
	}
	@RequestMapping("searchStyleList")
	@ResponseBody
	public List<YgStyle> searchStyleList() {	
		
		return ygStyleService.find();
	}
	
	@RequestMapping("saveStyle")
	@ResponseBody
	public Message saveStyle(String styleName,Long id,String remark) {
		YgStyle ygStyle=new YgStyle();
		ygStyle.setStyleName(styleName);
		ygStyle.setId(id);
		ygStyle.setRemark(remark);
		ygStyle.setSupplierId(getSession().getSupplierId());
		ygStyle.setCreateBy(getSession().getTrueName());
		ygStyle.setCreateTime(new Date());
	   return ygStyleService.saveOrUpdate(ygStyle)==1?SUCCESS_MESSAGE:ERROR_MESSAGE;
	
	}
	@RequestMapping("updateStyleStatus")
	@ResponseBody
	public Message updateStyleStatus(Long id) {
		YgStyle ygStyle=new YgStyle();		
		ygStyle.setId(id);
		ygStyle.setUpdateBy(getSession().getTrueName());	
		ygStyle.setUpdateTime(new Date());	
		ygStyle.setStatus(DataStatus.Delete);
	   return ygStyleService.update(ygStyle)==1?SUCCESS_MESSAGE:ERROR_MESSAGE;
	
	}
	
}
